package org.hxzon.demo.nioserver.apps.echo;

import java.nio.ByteBuffer;

import org.hxzon.nioserver.ChannelFacade;
import org.hxzon.nioserver.InputHandler;
import org.hxzon.nioserver.InputQueue;
import org.hxzon.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EchoHandler implements InputHandler {
    private final Logger logger=LoggerFactory.getLogger(EchoHandler.class);
    
    public ByteBuffer nextMessage(ChannelFacade channelFacade) {
        InputQueue inputQueue = channelFacade.inputQueue();
        return inputQueue.nextByteBuffer();
    }

    public void handleInput(ByteBuffer message, ChannelFacade channelFacade) {
        logger.trace("handleInput thread");
        String str = Util.readString(message);
        Util.println("rec:" + str);
        channelFacade.outputQueue().enqueue(message);
    }

    public void starting(ChannelFacade channelFacade) {
        // nothing
    }

    public void started(ChannelFacade channelFacade) {
        // nothing
    }

    public void endOfInput(ChannelFacade channelFacade) {
        // nothing
    }

    public void stopping(ChannelFacade channelFacade) {
        // nothing
    }

    public void stopped(ChannelFacade channelFacade) {
        // nothing
    }
}
